/**
 * 上海中赢金融信息服务有限公司
 * Copyright (c) 2017-2027 Chinazyjr,Inc.All Rights Reserved.
 */
package com.sys.midware.hive.handler;

import java.sql.Connection;

import com.sys.midware.hive.config.BHiveConfigUtil;
import com.sys.midware.hive.pool.ConnectionPoolManager;
import com.sys.midware.hive.pool.IConnectionPool;
import com.sys.midware.logger.Logger;
import com.sys.midware.logger.LoggerFactory;

/**
 * <b>Description：</b> hiveFactory <br/>
 * <b>ClassName：</b> HiveFactory <br/>
 * <b>@author：</b> mobing <br/>
 * <b>@date：</b> 2017年1月24日 下午2:47:00 <br/>
 * <b>@version: </b>  <br/>
 */
public class HiveFactory {
    private static final Logger logger = LoggerFactory.getLogger(HiveFactory.class);

    private static HiveFactory facotry = new HiveFactory();

    private HiveFactory() {
    }

    public static HiveFactory getInstance() {
        return facotry;
    }
    /**
     * 获取jdbc连接
     * getConnection <br/> 
     * @return  Connection <br/>
     */
    public Connection getConnection(String nodeName){
        BHiveConfigUtil.initConfig();
        Connection con =null;
        try {
            con= ConnectionPoolManager.getInstance().getConnection(nodeName);
        } catch (Exception e) {
            logger.error(e);
        }
        return con;
        
    }
    
    public IHiveHandler getDBHandler(String nodeName) throws Exception {
        IConnectionPool pool = ConnectionPoolManager.getInstance().getPool(nodeName);
        
        return new HiveHandler4JDBC(pool);
    }

    
//    public IHiveHandler getDBHandler(String nodeName) throws Exception {
//        DruidDataSource dataSource = new DruidDataSource();
//        
//        Properties p = new Properties();  
//        p.setProperty("driverClassName", "org.apache.hive.jdbc.HiveDriver");
//        p.setProperty("url", "jdbc:hive2://10.1.2.106:2181,10.1.2.107:2181,10.1.2.108:2181/whdb;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2_zk");
//        p.setProperty("username", "devops");
//        p.setProperty("password", "Hmc@1001");
//        p.setProperty("initialSize", "10");
//        p.setProperty("maxActive", "30");
//        p.setProperty("minIdle", "1");
//        p.setProperty("maxWait", "10000");
//        DruidDataSourceFactory.createDataSource(p);  
//        return new HiveHandler4JDBC(dataSource);
//    }

    public void shutdown() throws Exception {
        facotry = null;
    }

}
